<!--# layout("/layout/weui.html",{}){  #-->
<link rel="stylesheet" href="${base}/resources/editormd/css/editormd.css">
<header class='demos-header'>
	<h1 class="demos-title">回复帖子</h1>
</header>
<div class="weui_cells_title">回复内容</div>
<input type="hidden" id="topicId" value="${obj.data.id!}" />
<div class="weui_cells weui_cells_form">
	<div class="weui_cell">
		<div class="weui_cell_bd weui_cell_primary" id="editor">
			<textarea class="weui_textarea" id="text-input" placeholder="请输入内容" rows="8" style="display:none;"></textarea>
			<div class="weui_textarea_counter">
				<span>0</span>/200
			</div>
		</div>
	</div>
</div>
<div id="preview"></div>
<div class="weui_btn_area">
	<button class="weui_btn weui_btn_primary" id="reply-btn">确定</button>
</div>
<script src="${base!}/resources/editormd/js/editormd.min.js"></script>
<script type="text/javascript">
<!--
var testEditor;
$(function () {
    testEditor = editormd("editor", {
        width: "90%",
        height: 300,
        watch: false,
        path: '${base!}/resources/editormd/lib/',
        width: "90%",
        markdown: "",
        saveHTMLToTextarea : true,
        //dialogLockScreen : false,   // 设置弹出层对话框不锁屏，全局通用，默认为 true
        //dialogShowMask : false,     // 设置弹出层对话框显示透明遮罩层，全局通用，默认为 true
        //dialogDraggable : false,    // 设置弹出层对话框不可拖动，全局通用，默认为 true
        //dialogMaskOpacity : 0.4,    // 设置透明遮罩层的透明度，全局通用，默认值为 0.1
        //dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色，全局通用，默认为 #fff
        imageUpload: true,
        imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
        imageUploadURL: "${base!}/qa/upload",
        toolbarIcons: function () {
            return ["undo", "redo", "|", "bold", "del", "italic", "quote", "ucwords", "help", "info", "list-ul",
                "list-ol", "hr", "|",
                "link", "image", "code", "table", "datetime", "emoji", "pagebreak", "|", "preview", "clear"]
        }
    });
    $('#reply-btn').on('click', function () {
        $.post('${base!}/qa/reply', {
            id: $('#topicId').val(),
            content: testEditor.getHTML()
        }, function (result) {
        	if(result.operationState=='SUCCESS'){
        		$.toast("回复成功!", function() {
					location.href = '${base!}/qa/topic/detail/'+$('#topicId').val();
				});
        	}else{
        		$.toast(result.data.reason, "forbidden");
        	}
        }, 'json');
    });
});
//-->
</script>
<!--# } #-->